<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="__EXTEND__/favicon.ico" >
    <link rel="Shortcut Icon" href="__EXTEND__/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="__EXTEND__/lib/html5shiv.js"></script>
    <script type="text/javascript" src="__EXTEND__/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="__EXTEND__/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>宝贝列表</title>
    <link href="__EXTEND__/lib/lightbox2/2.8.1/css/lightbox.css" rel="stylesheet" type="text/css" >
    <link href="__EXTEND__/ztree/styles/zTree/zTreeStyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 宝贝管理 <span class="c-gray en">&gt;</span> 宝贝列表
    <a class="btn btn-default radius r " id="btn-refresh" style="line-height:1.6em;margin-top:3px" href="{{:U('Admin/Goods/goodsList')}}" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">

    <form id="searchform" action="{{:U('Admin/Goods/goodsList')}}" method="post">
        <div class="cl">
            <span >宝贝名称</span>
            <input type="text" id="goods_name" placeholder="支持模糊搜索" name="goods_name" value="{{$searchs['goods_name']}}" class="input-text" style="width:150px" >
            <span >宝贝分类</span>
            <span>
                <input type="text" id="cat_name" readonly="readonly" placeholder="清空则搜索全部宝贝" name="cat_name" nowvalue="{{$searchs['cat_name']}}" value="{{$searchs['cat_name']}}" class="input-text" style="width:200px" >
                <input type="hidden" id="cat_id" name="cat_id" value="{{$searchs['cat_id']}}">
            </span>
            <span>所属品牌</span>
            <span class="select-box inline">
                <select name="brand_id" style="width:150px" class="select" id="brand_id">
                   <option value="">请选择品牌(请先选择宝贝分类)</option>
                    <foreach name="search_brand" item="brand">
                        <option value="{{$brand['brand_id']}}" <if condition="$searchs['brand_id'] eq $brand['brand_id']">selected</if>>{{$brand['title']}}</option>
                    </foreach>
                </select>
            </span>
            <span >上架状态</span>
            <span class="select-box inline">
                <select name="is_up" class="select">
                    <option value="">全部宝贝</option>
                    <option value="1" <if condition="$searchs['is_up'] eq '1'">selected</if>>上架</option>
                    <option value="2" <if condition="$searchs['is_up'] eq '2'">selected</if>>下架</option>
                </select>
            </span>
            <span >热门推荐</span>
            <span class="select-box inline">
                <select name="is_hot" class="select">
                    <option value="">全部宝贝</option>
                    <option value="1" <if condition="$searchs['is_hot'] eq '1'">selected</if>>推荐</option>
                    <option value="0" <if condition="$searchs['is_hot'] eq '0'">selected</if>>不推荐</option>
                </select>
            </span>
            <button type="submit" class="btn btn-warning radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 筛选</button>
        </div>
        <div class="cl" style="margin-top:5px">


        </div>
    </form>
    <form class="form form-horizontal" id="form-multi"  method="post">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a class="btn btn-warning radius"  onclick="goods_add('添加宝贝','{{:U('Admin/Goods/goodsAdd',array('tag'=>'child'))}}')" href="javascript:;">
                <i class="Hui-iconfont">&#xe600;</i> 添加宝贝
            </a>

            <span class="select-box inline">
                <select name="multiOpera" class="select">
                    <option value="">请选择批量操作</option>
                    <option value="is_hot" <if condition="$searchs['multiOpera'] eq 'is_hot'">selected</if>>批量推荐</option>
                    <option value="not_hot" <if condition="$searchs['multiOpera'] eq 'not_hot'">selected</if>>批量不推荐</option>
                    <option value="is_up" <if condition="$searchs['multiOpera'] eq 'is_up'">selected</if>>批量上架</option>
                    <option value="not_up" <if condition="$searchs['multiOpera'] eq 'not_up'">selected</if>>批量下架</option>
                </select>
            </span>
            <input class="btn btn-warning radius" type="button" onclick="multiStatus()" value="&nbsp;&nbsp;执行&nbsp;&nbsp;" >
        </span>
            <span class="r">{{$page}}</span>
        </div>
        <table class="table table-border table-bordered table-bg mt-20 table-sort table-hover table-bg">
            <thead>
            <tr class="text-c">
                <th style="width:4%"><input type="checkbox" name="" value=""></th>
                <th width="10%">宝贝ID</th>
                <th width="20%">宝贝名称</th>
                <th width="10%">限时最高价</th>
                <th width="15%">宝贝分类</th>
                <th width="10%">所属品牌</th>
                <th width="10%">热门推荐</th>
                <th width="10%">上架状态</th>
                <th width="15%">操作</th>
            </tr>
            </thead>
            <tbody>
            <notempty name="lists">
                <foreach name="lists" item="list">
                    <tr class="text-c">
                        <td ><input type="checkbox" value="{{$list['goods_id']}}" name="goods_id[]"></td>
                        <td>{{$list['goods_id']}}</td>
                        <td class="text-l">{{$list['goods_name']}}</td>
                        <td >￥{{$list['highest_price']}}</td>
                        <td >{{$list['cat_name']}}</td>
                        <td >{{$list['brand_title']}}</td>
                        <td class="td-status_hot">
                            <switch name="list['is_hot']">
                                <case value="1"><span style="cursor:pointer" title="点击" class="label label-success radius" onClick="goods_not_hot(this,{{$list['goods_id']}})">推荐</span></case>
                                <case value="0"><span style="cursor:pointer" title="点击" class="label label-default radius" onClick="goods_is_hot(this,{{$list['goods_id']}})">不推荐</span></case>
                            </switch>
                        </td>
                        <td class="td-status_up">
                            <switch name="list['is_up']">
                                <case value="1"><span class="label label-success radius">已上架</span></case>
                                <case value="2"><span class="label label-defaunt radius">已下架</span></case>
                            </switch>
                        </td>
                        <td class="td-manage">
                            <if condition="$list['is_up'] eq 1">
                                <a style="text-decoration:none" onClick="goods_down(this,{{$list['goods_id']}})" href="javascript:;" title="下架">
                                    <i class="Hui-iconfont">&#xe6de;</i>
                                </a>
                                <elseif condition="$list['is_up'] eq 2"/>
                                <a style="text-decoration:none" onClick="goods_up(this,{{$list['goods_id']}})" href="javascript:;" title="上架">
                                    <i class="Hui-iconfont">&#xe603;</i>
                                </a>
                            </if>
                            <a style="text-decoration:none" class="ml-5" onClick="goods_edit('编辑','{{:U('Admin/Goods/goodsEdit',array('goods_id'=>$list['goods_id'],'p'=>$p))}}')" href="javascript:;" title="编辑">
                                <i class="Hui-iconfont">&#xe6df;</i>
                            </a>
                            <a title="删除" href="javascript:;" onclick="goods_del(this,{{$list['goods_id']}})" class="ml-5" style="text-decoration:none">
                                <i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                </foreach>
                <else/>
                <tr><td colspan="65" class="text-center">  暂时还没有内容! </td></tr>
            </notempty>
            <tr >
                <th scope="col" colspan="15">
                    <span class="r">{{$page}}</span>
                </th>
            </tr>
            </tbody>
        </table>
    </form>
</div>
<!--_footer 作为公共模版分离出去-->
<!--<script type="text/javascript" src="__EXTEND__/lib/jquery/1.9.1/jquery.min.js"></script>-->
<script type="text/javascript" src="__EXTEND__/js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__EXTEND__/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="__EXTEND__/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->
<script type="text/javascript" src="__EXTEND__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__EXTEND__/lib/lightbox2/2.8.1/js/lightbox.min.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__EXTEND__/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/laypage/1.2/laypage.js"></script>



<script type="text/javascript">
    {{:C("URL_HTML_SUFFIX","")}}
    function multiStatus(){
        layer.confirm('确认执行批量操作吗？',function(index) {
            var method = $("select[name='multiOpera']").val();
            if(method == ''){
                layer.msg('请选择执行操作', {icon: 2, time: 1000});
            }else{
                $("#form-multi").ajaxSubmit({
                    type: 'post',
                    url: "{{:U('Admin/Goods/multiOpera')}}"+'/method/'+method,
                    success: function (data) {
                        if (data.status) {
                            layer.msg(data.info, {icon: 6, time: 1000});
                            setTimeout((function () {
                                window.location.href = "{{:U('Admin/Goods/goodsList',array('p'=>$p))}}";
                            }), 1500);
                        } else {
                            layer.msg(data.info, {icon: 2, time: 1000});
                        }
                    },
                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                        layer.msg('操作失败', {icon: 5, time: 1000});
                    }
                });
            }

        });
    }
    $(function(){
        $(".portfolio-area li").Huihover();
    });

    /*宝贝-编辑*/
    function goods_edit(title,url){
        layer_full(title,url);
    }

    /*宝贝-删除*/
    function goods_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: '{{:U("Admin/Goods/deleteGoods")}}',
                data: {
                    id : id
                },
                dataType: 'json',
                success: function(data){
                    if(data.status){
                        $(obj).parents("tr").remove();
                        layer.msg(data.info,{icon:1,time:1000});
//                        setTimeout((function() {
//                            window.location.href="{{:U('Admin/Goods/goodsList',array('p'=>$p))}}";
//                        }), 500);
                    }else{
                        layer.msg(data.info,{icon:2,time:1000});
                    }
                },
                error:function(data) {
                    console.log(data.msg);
                },
            });
        });
    }

    /*上架*/
    function goods_down(obj,id){
        layer.confirm('确认要下架吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: "POST",
                url: "{{:U('Admin/Goods/updateStatus')}}"+'/method/downGoods',
                data: {
                    id : id
                },
                timeout:180000,
                dataType: "JSON",
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('操作失败!',{icon: 5,time:1000});
                },
                success: function(msg){
                    if(msg["status"]==1){
                        $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="goods_up(this,'+id+')" href="javascript:;" title="上架"><i class="Hui-iconfont">&#xe603;</i></a>');
                        $(obj).parents("tr").find(".td-status_up").html('<span class="label label-defaunt radius">已下架</span>');
                        $(obj).remove();
                        layer.msg('已下架!',{icon: 6,time:1000});
                    }else{
                        layer.msg(msg.info,{icon: 5,time:1000});
                    }
                }
            });
        });
    }
    /*下架*/
    function goods_up(obj,id){
        layer.confirm('确认要上架吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: "POST",
                url: "{{:U('Admin/Goods/updateStatus')}}"+'/method/upGoods',
                data: {
                    id : id
                },
                timeout:180000,
                dataType: "JSON",
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('操作失败!',{icon: 5,time:1000});
                },
                success: function(msg){
                    if(msg["status"]==1){
                        $(obj).parents("tr").find(".td-manage").prepend('<a onClick="goods_down(this,'+id+')" href="javascript:;" title="下架" style="text-decoration:none"><i class="Hui-iconfont">&#xe6de;</i></a>');
                        $(obj).parents("tr").find(".td-status_up").html('<span class="label label-success radius">已上架</span>');
                        $(obj).remove();
                        layer.msg('已上架!', {icon: 6,time:1000});
                    }else{
                        layer.msg(msg.info,{icon: 5,time:1000});
                    }
                }
            });
        });
    }
    /*热门推荐*/
    function goods_is_hot(obj,id){
        layer.confirm('确认要推荐吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: "POST",
                url: "{{:U('Admin/Goods/updateStatus')}}"+'/method/isHot',
                data: {
                    id : id
                },
                timeout:180000,
                dataType: "JSON",
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('操作失败!',{icon: 5,time:1000});
                },
                success: function(msg){
                    if(msg["status"]==1){
                        layer.close(index);
                        $(obj).parents("tr").find(".td-status_hot").html('<span style="cursor:pointer" title="点击"  class="label label-success radius" onClick="goods_not_hot(this,'+id+')">推荐</span>');
                        $(obj).remove();
                    }else{
                        layer.msg(msg.info,{icon: 5,time:1000});
                    }
                }
            });
        });
    }
    /*热门不推荐*/
    function goods_not_hot(obj,id){
        layer.confirm('确认不推荐吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: "POST",
                url: "{{:U('Admin/Goods/updateStatus')}}"+'/method/notHot',
                data: {
                    id : id
                },
                timeout:180000,
                dataType: "JSON",
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('操作失败!',{icon: 5,time:1000});
                },
                success: function(msg){
                    if(msg["status"]==1){
                        layer.close(index);
                        $(obj).parents("tr").find(".td-status_hot").html('<span style="cursor:pointer" title="点击"  class="label label-default radius"  onClick="goods_is_hot(this,'+id+')">不推荐</span>');
                        $(obj).remove();
                    }else{
                        layer.msg(msg.info,{icon: 5,time:1000});
                    }
                }
            });
        });
    }



    /*宝贝-添加*/
    function goods_add(title,url){
        layer_full(title,url);
    }

</script>

<!--<script type="text/javascript" src="__EXTEND__/ztree/js/jquery-1.6.2.min.js" ></script>-->
<script type="text/javascript" src="__EXTEND__/ztree/js/jquery.ztree.all-3.5.min.js" ></script>
<script type="text/javascript" src="__EXTEND__/ztree/js/category_selecter.js" ></script>

<script type="text/javascript">
    $().ready(function(){
        $.ajaxCategorySelecter("{{:U('Admin/Category/ajax_category')}}",$("#cat_name"), $("#cat_id"), "{{$goods_cat_id}}",'1');//1-需要移动
    });
    /*存在品牌选项则对应动态生成品牌选择项*/
    function changeBrandList(cat_id){
        var target_obj = $("#brand_id");
        if(target_obj.length>0 && cat_id != ''){
            $.ajax({
                type: 'POST',
                url: '{{:U("Admin/Brand/getBrandByCat")}}',
                data: {
                    cat_id:cat_id,
                },
                dataType: 'json',
                success: function(data){
                    if(data.status){
                        var brand_html = '<option value="">请选择品牌(请先选择宝贝分类)</option>';
                        $(data.info).each(function(i, v){
                            brand_html += '<option value="' + v.brand_id + '">' + v.title + '</option>';
                        });
                        target_obj.html(brand_html);
                        return;
                    }else{
                        layer.msg(data.info,{icon:2,time:1000});
                    }
                },
                error:function(data) {
                    console.log(data.msg);
                },
            });
        }
    }
</script>
</body>
</html>